package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.MemberTagEntity;
import com.topscore.uke.mvp.contractors.GetMemberTagsContractor;
import com.topscore.uke.mvp.model.GetMemberTagsInfoModel;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.ui.loadsir_callback.EmptyCallBack;
import com.topscore.uke.ui.loadsir_callback.ErrorCallBack;
import com.topscore.uke.ui.loadsir_callback.LoadingCallBack;

import java.util.List;

/**
 * Created by 71468 on 2018/3/23.
 */

public class GetMemberTagsInfoPresenter implements GetMemberTagsContractor, GetMemberTagsContractor.Presenter {

    private View mView;

    public GetMemberTagsInfoPresenter(View view) {
        this.mView = view;
    }

    @Override
    public void getTags(String id) {
        mView.getLoadService().showCallback(LoadingCallBack.class);
        new GetMemberTagsInfoModel(new CallBack() {
            @Override
            public void onSuccess(BaseResponse<List<MemberTagEntity>> response) {
                if (response.getData() != null && response.getData().size() > 0) {
                    mView.getRootRecycler().setNewData(response.getData());
                    String[] tabTitles = new String[response.getData().size()];
                    for (int i = 0; i < response.getData().size(); i++) {
                        tabTitles[i] = response.getData().get(i).getBasisDictionaryVo().getValueName();
                    }
                    mView.setTabs(tabTitles);
                } else {
                    mView.getLoadService().showCallback(EmptyCallBack.class);
                }
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode, errorMessage);
                mView.getLoadService().showCallback(ErrorCallBack.class);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
                mView.getLoadService().showSuccess();
            }
        }).getTags(id);
    }
}
